package com.whfc.common.file;


import com.whfc.common.util.MathUtil;

/**
 * @Description 文件长度解析
 * @Author hw
 * @Date 2021-07-23 10:17
 * @Version 1.0
 */
public enum FileSizeType {

    KB(1024, "KB"),
    MB(1024 * 1024, "MB"),
    GB(1024 * 1024 * 1024, "GB");

    private Integer value;

    private String unit;

    FileSizeType(Integer value, String unit) {
        this.value = value;
        this.unit = unit;
    }

    public static String getFileSize(Integer size) {
        String fileSize = "";
        if (size >= GB.value) {
            Double c = MathUtil.divide(size, GB.value, 2);
            fileSize = c + GB.unit;
        } else if (size >= MB.value) {
            Double c = MathUtil.divide(size, MB.value, 2);
            fileSize = c + MB.unit;
        } else if (size >= KB.value) {
            Double c = MathUtil.divide(size, KB.value, 2);
            fileSize = c + KB.unit;
        }
        return fileSize;
    }

}
